<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
if($basic['no_up']){
	exi('本系统不支持上传相册！','error');
}
set_html('title','上传相册');
if($_RQ['op']=='main'){
	//查询在进行的项目
	$rid = intval($_RQ['rid']);
	$post=array();
		$list=pdo_getall('jy_cmsphoto_classify',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title'),'id');
		if($list){
			foreach($list as &$row){
				$row=$row['title'];
			}
		}
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if(!$postdata['title']){
			exi('相册标题不能为空！','error');
		}
		if(!$postdata['cid']){
			exi('请选择分类！','error');
		}
		if(!$postdata['description']){
			exi('相册描述不能为空！','error');
		}
		
		if(!$postdata['images']){
			exi('相册图片不能为空！','error');
		}

		//判断字段必填
		if(!empty($postdata['fileds'])){
			foreach($postdata['fileds'] as $item){
				if($item['is_must'] && empty($item['data'])){
					exi('请填写:'.$item['title'],'error');
				}
			}
		}
		if($basic['shenhe']){
			$status=0;
		}else{
			$status=1;
		}
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'cid'=>$postdata['cid'],
			'title'=>$postdata['title'],
			'status'=>$status,
			'image'=>$postdata['images']['0'],
			'remark'=>$postdata['description'],
			'images'=>ijson_encode($postdata['images']),
		//	'fileddata'=>ijson_encode($postdata['fileds']),
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_cmsphoto_photo',$insert);
		$id=pdo_insertid();
		if($basic['shenhe']){
			exi('上传相册成功,等待管理员审核','success','jy_cmsphoto/index/list');
		}else{
			exi('上传相册成功','success','jy_cmsphoto/index/list');
		}
	}
	$post['images']=array();
	$return['post']=$post;
	$return['list']=$list;
	$return['province']=cfc('tools')->pcd();
	exi($return);

}
if($_RQ['op']=='getfileds'){
	//查询自定义字段
	$fileds=pdo_getcolumn('jy_vote_reply',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'fileds');
	$fileds = json_decode($fileds,true);
	foreach($fileds as &$item){
		$item['value']=explode(';',$item['value']);
	}
	$return['post']=array();
	$return['post']['fileds']=$fileds;
	$return['success']=1;
	exi($return);
}